package com.yntx.usercenter.authentication.service;

import cn.hutool.crypto.digest.BCrypt;
import org.springframework.stereotype.Component;

/**
 * 密码bcrypt编码器
 *
 * @author wuzhengyu
 * @date 2023/05/10 14:23
 */
@Component
public class PasswordBCryptEncoder {

    /**
     * 编码
     *
     * @param password 密码
     * @return {@link String}
     */
    public String encode(String password) {
        String salt = BCrypt.gensalt();
        return BCrypt.hashpw(password, salt);
    }

    /**
     * 匹配
     *
     * @param password       密码
     * @param encodePassword 编码密码
     * @return boolean
     */
    public boolean match(String password, String encodePassword) {
        return BCrypt.checkpw(password, encodePassword);
    }

}
